package com.csoa.community.activity;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.collect.community.R;
import com.csoa.community.bean.YFInfoBean;
import com.csoa.community.datepicker.OnWheelChangedListener;
import com.csoa.community.datepicker.WheelView;
import com.csoa.community.datepicker.adapter.NumericWheelAdapter;
import com.csoa.community.db.YFInfoDB;
import com.csoa.community.singletons.GlobalVars;
import com.csoa.community.utils.StringUtils;

public class YFInfoActivity extends BaseProcessPhotoActivity {

	public YFInfoBean mYFInfo;
	private Spinner mSpinnerAreaYF;
	private EditText mEtXiangZhenYF;
	private EditText mEtCunYF;
	private EditText metDateYF;
	private EditText etGridNumberYF;
	private EditText etLongitudeYF;
	private EditText etLatitudeYF;
	private EditText etelevationtYF;
	private EditText etSlopeYF;
	private EditText etenvironmentFeatureYF;
	private EditText etquadratsNumberYF;
	private EditText etquadratAreaYF;
	private EditText etsmallQuadratAreaYF;
	private EditText ettreeLayerCoverageYF;
	private EditText etShuGanCoverageYF;
	private EditText etKuZhiCoverageYF;
	private EditText etGuanMuCoverageYF;
	private EditText etCaoMuCoverageYF;
	private EditText etcommunityYF;
	private EditText etsurfaceFeaturesYF;
	private EditText etInvestigatorsYF;
	private EditText etinterferenceYF;
	private EditText etTanXianCoverageYF;
	private EditText etaspectYF;
	private EditText etslopePositionYF;
	private View mViewDatePicker;
	private Animation mAnimationPushUpIn;
	private Animation mAnimationPushUpOut;
	private int START_YEAR;
	private int END_YEAR;
	private int mPosition;
	private TextView mTVCurrentPage;
	private Animation mAnimationLeftIn;
	private Animation mAnimationRightIn;
	private View view;

	@Override
	public void initUI() {
		mYFInfo = (YFInfoBean) this.getIntent().getSerializableExtra("YFInfo");
		mPosition = this.getIntent().getIntExtra("position", 0);
		mWhich = this.getIntent().getIntExtra("which", 0);
		switch (mWhich) {
		case 0:// 查看
			setContentView(R.layout.yf_info_see);
			this.findViewById(R.id.layoutButton).setVisibility(View.VISIBLE);
			break;
		case 1:// 添加
			setContentView(R.layout.yf_info);
			this.findViewById(R.id.layoutButton).setVisibility(View.VISIBLE);
			this.findViewById(R.id.btnDelYF).setVisibility(View.GONE);
			break;
		case 2:
			break;
		case 3:// 修改
			setContentView(R.layout.yf_info);
			this.findViewById(R.id.layoutButton).setVisibility(View.VISIBLE);
			break;
		case 4:
			break;

		default:
			break;
		}
		if (GlobalVars.getInst().latitude == 0.0) {
			initMapLocation();
		}

		mViewDatePicker = this.findViewById(R.id.layout_datepicker);

		mAnimationPushUpIn = AnimationUtils.loadAnimation(this,
				R.anim.slide_up_in);
		mAnimationPushUpOut = AnimationUtils.loadAnimation(this,
				R.anim.slide_down_out);

		this.findViewById(R.id.btnSaveYF).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if (mWhich == 0) {
							prePage();
							return;
						}
						saveYFInfo();
					}
				});

		this.findViewById(R.id.btnDelYF).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if (mWhich == 0) {
							nextPage();
							return;
						}
						new AlertDialog.Builder(YFInfoActivity.this)
								.setMessage("确认删除吗?")
								.setPositiveButton("确定", new OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										YFInfoDB.delete(mYFInfo);
										showToast("删除成功");
										Intent intent = new Intent();
										intent.putExtra("delete", mYFInfo);
										intent.putExtra("position", mPosition);
										setResult(RESULT_OK, intent);
										finish();
									}
								}).setNegativeButton("取消", null).show();

					}
				});

		this.findViewById(R.id.btnBackYF).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						finish();
					}
				});
		this.findViewById(R.id.btnLocateYF).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						startLocation();
					}
				});

		layoutCameraYF = (LinearLayout) this.findViewById(R.id.layoutCameraYF);

		this.findViewById(R.id.btnCameraYF).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(YFInfoActivity.this,
								CameraActivity.class);
						String imgName = getImgName(true);
						String imgPath = getImgPath(true);
						intent.putExtra("imgPath", imgPath);
						intent.putExtra("imgName", imgName);
						intent.putExtra("title", imgTitle);
						intent.putExtra("author", imgAuthor);
						startActivityForResult(intent, 1);
					}
				});

		layoutVedioYF = (LinearLayout) this.findViewById(R.id.layoutVedioYF);
		
		this.findViewById(R.id.btnVedioYF).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						String imgName = getImgName(false);
						String imgPath = getImgPath(false);
						Intent intent = new Intent(YFInfoActivity.this,
								VideoActivity.class);
						intent.putExtra("imgPath", imgPath);
						intent.putExtra("imgName", imgName);
						intent.putExtra("title", videoTitle);
						intent.putExtra("author", videoAuthor);
						startActivityForResult(intent, 2);
					}
				});

		//
		mSpinnerAreaYF = (Spinner) this.findViewById(R.id.spinnerAreaYF);
		//
		mEtXiangZhenYF = (EditText) this.findViewById(R.id.etXiangZhenYF);
		//
		mEtCunYF = (EditText) this.findViewById(R.id.etCunYF);
		
		metDateYF = (EditText) this.findViewById(R.id.etDateYF);

		metDateYF.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				showDateTimePicker(metDateYF);
			}
		});
		metDateYF.setOnFocusChangeListener(new OnFocusChangeListener() {
			
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				showDateTimePicker(metDateYF);
			}
		});
		etGridNumberYF = (EditText) this.findViewById(R.id.etGridNumberYF);

		etLongitudeYF = (EditText) this.findViewById(R.id.etLongitudeYF);
		etLatitudeYF = (EditText) this.findViewById(R.id.etLatitudeYF);
		etelevationtYF = (EditText) this.findViewById(R.id.etelevationtYF);
		
		etaspectYF = (EditText) this.findViewById(R.id.etaspectYF);
		etSlopeYF = (EditText) this.findViewById(R.id.etSlopeYF);
		etslopePositionYF = (EditText) this
				.findViewById(R.id.etslopePositionYF);
		etenvironmentFeatureYF = (EditText) this
				.findViewById(R.id.etenvironmentFeatureYF);
		etquadratsNumberYF = (EditText) this
				.findViewById(R.id.etquadratsNumberYF);
		etquadratAreaYF = (EditText) this.findViewById(R.id.etquadratAreaYF);
		
		etsmallQuadratAreaYF = (EditText) this
				.findViewById(R.id.etsmallQuadratAreaYF);
		ettreeLayerCoverageYF = (EditText) this
				.findViewById(R.id.ettreeLayerCoverageYF);
		etGuanMuCoverageYF = (EditText) this
				.findViewById(R.id.etGuanMuCoverageYF);
		etCaoMuCoverageYF = (EditText) this
				.findViewById(R.id.etCaoMuCoverageYF);
		etKuZhiCoverageYF = (EditText) this
				.findViewById(R.id.etKuZhiCoverageYF);
		etTanXianCoverageYF = (EditText) this
				.findViewById(R.id.etTanXianCoverageYF);
		etShuGanCoverageYF = (EditText) this
				.findViewById(R.id.etShuGanCoverageYF);
	
		etcommunityYF = (EditText) this.findViewById(R.id.etcommunityYF);
		etinterferenceYF = (EditText) this.findViewById(R.id.etinterferenceYF);
		etsurfaceFeaturesYF = (EditText) this
				.findViewById(R.id.etsurfaceFeaturesYF);
		etInvestigatorsYF = (EditText) this
				.findViewById(R.id.etInvestigatorsYF);
		
		fillData();
		if(mWhich == 0) {
			view = this.findViewById(R.id.scroller);
			view.setOnTouchListener(this);
			mAnimationLeftIn = AnimationUtils.loadAnimation(this,
					R.anim.slide_left_in);
			mAnimationRightIn = AnimationUtils.loadAnimation(this,
					R.anim.slide_right_in);
			modifyEditStyle();
			mTVCurrentPage = (TextView)this.findViewById(R.id.currentPage);
			updatePage();
		}

	}
	
	public void updatePage() {
		if(mTVCurrentPage != null) {
			mTVCurrentPage.setText((mPosition + 1) + "/" + YFInfoTableActivity.mYFInfos.size());
		}
		
	}
	
	
	@Override
	protected void ProcessPrePage() {
		prePage();
	}
	
	@Override
	protected void ProcessNextPage() {
		nextPage();
	}
	
	protected void prePage() {
		if (mPosition == 0) {
			showToast("没有更多样方了.");
			return;
		}
		view.startAnimation(mAnimationRightIn);
		mYFInfo = YFInfoTableActivity.mYFInfos
				.get(mPosition - 1);
		mPosition--;
		fillData();
		updatePage();
	}

	/**
	 * 上一页
	 */
	protected void nextPage() {
		if (mPosition == YFInfoTableActivity.mYFInfos
				.size() - 1) {
			showToast("没有更多样方了.");
			return;
		}
		view.startAnimation(mAnimationLeftIn);
		mYFInfo = YFInfoTableActivity.mYFInfos
				.get(mPosition + 1);
		mPosition++;
		fillData();
		updatePage();
	}
	
	
	public void fillData() {
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.imgPath)) {
			String[] strImgInfo = mYFInfo.imgPath.split(":");
			sbImgUrl = new StringBuffer("");
			sbImgName = new StringBuffer("");
			sbImgUrl.append(strImgInfo[0]);
			sbImgName.append(strImgInfo[1]);
			fillBitmapToLayout(sbImgUrl.toString(),sbImgName.toString(), layoutCameraYF, true);
		}else {
			layoutCameraYF.removeAllViews();
		}
		if(mYFInfo != null) {
			imgTitle = mYFInfo.imgTitle;
			imgAuthor = mYFInfo.imgAuthor;
			
			videoTitle = mYFInfo.videoTitle;
			videoAuthor = mYFInfo.videoAuthor;
		}
		
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.videoPath)) {
			String[] strVideoInfo = mYFInfo.videoPath.split(":");
			sbVideoUrl = new StringBuffer("");
			sbVideoName = new StringBuffer("");
			sbVideoUrl.append(strVideoInfo[0]);
			sbVideoName.append(strVideoInfo[1]);
			fillBitmapToLayout(sbVideoUrl.toString(),sbVideoName.toString(), layoutVedioYF, false);
		}else {
			layoutVedioYF.removeAllViews();
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.xiang)) {
			mEtXiangZhenYF.setText(mYFInfo.xiang.toString());
		}else {
			mEtXiangZhenYF.setText("");
		}
		if (mYFInfo != null) {
			mSpinnerAreaYF.setSelection(mYFInfo.areaPosition);
		}else {
			mSpinnerAreaYF.setSelection(0);
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.country)) {
			mEtCunYF.setText(mYFInfo.country.toString());
		}else {
			mEtCunYF.setText("");
		}
		//
		if (mWhich == 1) {
			metDateYF.setText(getCurrentTime());
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.date)) {
			metDateYF.setText(mYFInfo.date.toString());
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.gridNumber)) {
			etGridNumberYF.setText(mYFInfo.gridNumber.toString());
		}else {
			etGridNumberYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.longitude)) {
			etLongitudeYF.setText(mYFInfo.longitude.toString());
		} else {
			etLongitudeYF.setText(GlobalVars.getInst().longitude + "");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.latitude)) {
			etLatitudeYF.setText(mYFInfo.latitude.toString());
		} else {
			etLatitudeYF.setText(GlobalVars.getInst().latitude + "");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.elevation)) {
			etelevationtYF.setText(mYFInfo.elevation.toString());
		} else {
			etelevationtYF.setText(GlobalVars.getInst().altitude + "");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.aspect)) {
			etaspectYF.setText(mYFInfo.aspect.toString());
		}else {
			etaspectYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.slope)) {
			etSlopeYF.setText(mYFInfo.slope.toString());
		}else {
			etSlopeYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.slopePosition)) {
			etslopePositionYF.setText(mYFInfo.slopePosition.toString());
		}else {
			etslopePositionYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.environmentFeature)) {
			etenvironmentFeatureYF.setText(mYFInfo.environmentFeature
					.toString());
		}else {
			etenvironmentFeatureYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.quadratsNumber)) {
			etquadratsNumberYF.setText(mYFInfo.quadratsNumber.toString());
		}else {
			etquadratsNumberYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.quadratArea)) {
			etquadratAreaYF.setText(mYFInfo.quadratArea.toString());
		}else {
			etquadratAreaYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.smallQuadratArea)) {
			etsmallQuadratAreaYF.setText(mYFInfo.smallQuadratArea.toString());
		}else {
			etsmallQuadratAreaYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.treeLayerCoverage)) {
			ettreeLayerCoverageYF.setText(mYFInfo.treeLayerCoverage.toString());
		}else {
			ettreeLayerCoverageYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.guanMuCoverage)) {
			etGuanMuCoverageYF.setText(mYFInfo.guanMuCoverage.toString());
		}else {
			etGuanMuCoverageYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.caoMuCoverage)) {
			etCaoMuCoverageYF.setText(mYFInfo.caoMuCoverage.toString());
		}else {
			etCaoMuCoverageYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.kuZhiCoverage)) {
			etKuZhiCoverageYF.setText(mYFInfo.kuZhiCoverage.toString());
		}else {
			etKuZhiCoverageYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.taiXianCoverage)) {
			etTanXianCoverageYF.setText(mYFInfo.taiXianCoverage.toString());
		}else {
			etTanXianCoverageYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.shuGanCoverage)) {
			etShuGanCoverageYF.setText(mYFInfo.shuGanCoverage.toString());
		}else {
			etShuGanCoverageYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.community)) {
			etcommunityYF.setText(mYFInfo.community.toString());
		}else {
			etcommunityYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.interference)) {
			etinterferenceYF.setText(mYFInfo.interference.toString());
		}else {
			etinterferenceYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.surfaceFeatures)) {
			etsurfaceFeaturesYF.setText(mYFInfo.surfaceFeatures.toString());
		}else {
			etsurfaceFeaturesYF.setText("");
		}
		if (mYFInfo != null && !StringUtils.isEmpty(mYFInfo.investigators)) {
			etInvestigatorsYF.setText(mYFInfo.investigators.toString());
		}else {
			etInvestigatorsYF.setText("");
		}
	}

	protected void saveYFInfo() {
		String date = metDateYF.getText().toString().trim();
		if (StringUtils.isEmpty(date)) {
			showToast("您还没有选择日期");
			return;
		}
		String longitude = etLongitudeYF.getText().toString().trim();
		if (StringUtils.isEmpty(longitude)) {
			showToast("尚未获取到经度信息");
			return;
		}
		String latitude = etLatitudeYF.getText().toString().trim();
		if (StringUtils.isEmpty(latitude)) {
			showToast("尚未获取到纬度信息");
			return;
		}
		String quadratsNumber = etquadratsNumberYF.getText().toString().trim();
		if (StringUtils.isEmpty(quadratsNumber)) {
			showToast("您还没有填写样方号信息");
			return;
		}
		String community = etcommunityYF.getText().toString().trim();
		if (StringUtils.isEmpty(community)) {
			showToast("您还没有填写群落类型及组成信息");
			return;
		}

		final YFInfoBean yfInfo = new YFInfoBean();
		yfInfo.groupId = "123456";
		yfInfo.projectId = "wsj";
		yfInfo.surveyMethod = "样方法";
		yfInfo.gridNumber = etGridNumberYF.getText().toString();
		yfInfo.area = mSpinnerAreaYF.getSelectedItem().toString();
		yfInfo.areaPosition = mSpinnerAreaYF.getSelectedItemPosition();

		yfInfo.xiang = mEtXiangZhenYF.getText().toString();
		yfInfo.country = mEtCunYF.getText().toString();
		yfInfo.date = metDateYF.getText().toString();
		yfInfo.quadratsNumber = etquadratsNumberYF.getText().toString();
		yfInfo.elevation = etelevationtYF.getText().toString();
		yfInfo.longitude = etLongitudeYF.getText().toString();
		yfInfo.latitude = etLatitudeYF.getText().toString();
		yfInfo.aspect = etaspectYF.getText().toString();
		yfInfo.slope = etSlopeYF.getText().toString();
		yfInfo.slopePosition = etslopePositionYF.getText().toString();
		yfInfo.quadratArea = etquadratAreaYF.getText().toString();
		yfInfo.smallQuadratArea = etsmallQuadratAreaYF.getText().toString();
		yfInfo.environmentFeature = etenvironmentFeatureYF.getText().toString();
		yfInfo.interference = etinterferenceYF.getText().toString();
		yfInfo.treeLayerCoverage = ettreeLayerCoverageYF.getText().toString();

		yfInfo.guanMuCoverage = etGuanMuCoverageYF.getText().toString();
		yfInfo.caoMuCoverage = etCaoMuCoverageYF.getText().toString();
		yfInfo.kuZhiCoverage = etKuZhiCoverageYF.getText().toString();
		yfInfo.taiXianCoverage = etTanXianCoverageYF.getText().toString();
		yfInfo.shuGanCoverage = etShuGanCoverageYF.getText().toString();

		yfInfo.community = etcommunityYF.getText().toString();
		yfInfo.investigators = etInvestigatorsYF.getText().toString();
		yfInfo.surfaceFeatures = etsurfaceFeaturesYF.getText().toString();
		
		String imgName = getImgName(true);
		String imgPath = getImgPath(true);
		
		
		if (imgPath != null && !"".equals(imgPath.toString())) {
			yfInfo.imgPath = imgPath + ":" +  imgName;
		}
		yfInfo.imgTitle = imgTitle;
		yfInfo.imgAuthor = imgAuthor;
		
		
		String vedioName = getImgName(false);
		String vedioPath = getImgPath(false);
		if (vedioPath != null && !"".equals(vedioPath.toString())) {
			yfInfo.videoPath = vedioPath + ":" +  vedioName;
		}
		
		yfInfo.videoTitle = videoTitle;
		yfInfo.videoAuthor = videoAuthor;
		if(mYFInfo != null) {
			yfInfo.wzCount = mYFInfo.wzCount;
		}
		

		Intent intent = new Intent();
		if (mWhich == 1) {
			YFInfoDB.insert(yfInfo);
		} else if (mWhich == 3) {
			YFInfoDB.updateById(yfInfo, mYFInfo.id);
			intent.putExtra("update", yfInfo);
			intent.putExtra("position", mPosition);
		}
		showToast("保存成功");
		setResult(RESULT_OK, intent);
		finish();

	}

	@Override
	public void initData() {
		String[] strDataArea = GlobalVars.getInst().getArea();
		if (strDataArea != null) {
			ArrayAdapter<String> areaAdapter = new ArrayAdapter<String>(this,
					R.layout.item_spinner, strDataArea);
			areaAdapter
					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			mSpinnerAreaYF.setAdapter(areaAdapter);
			if (mYFInfo != null) {
				mSpinnerAreaYF.setSelection(mYFInfo.areaPosition);

			}
		}

	}

	/**
	 * @Description: TODO 弹出日期时间选择器
	 */
	private void showDateTimePicker(final TextView tv) {
		Date dateInput = new Date(System.currentTimeMillis());
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateInput);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DATE);
		View view = findViewById(R.id.layout_datepicker);

		// 年
		final WheelView wv_year = (WheelView) view.findViewById(R.id.year);
		START_YEAR = year - 3;
		END_YEAR = year + 8;
		wv_year.setViewAdapter(new NumericWheelAdapter(this, START_YEAR,
				END_YEAR, null, "年"));// 设置"年"的显示数据
		wv_year.setCurrentItem(year - START_YEAR);// 初始化时显示的数据

		// 月
		final WheelView wv_month = (WheelView) view.findViewById(R.id.month);
		wv_month.setViewAdapter(new NumericWheelAdapter(this, 1, 12, null, "月"));
		wv_month.setCyclic(true);
		wv_month.setCurrentItem(month);

		// 日
		final WheelView wv_day = (WheelView) view.findViewById(R.id.day);
		updateDays(START_YEAR, wv_year, wv_month, wv_day);
		wv_day.setCyclic(true);
		wv_day.setCurrentItem(day - 1);

		// 添加"年"监听
		OnWheelChangedListener wheelListener_year = new OnWheelChangedListener() {
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				updateDays(START_YEAR, wv_year, wv_month, wv_day);
			}
		};
		// 添加"月"监听
		OnWheelChangedListener wheelListener_month = new OnWheelChangedListener() {
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				updateDays(START_YEAR, wv_year, wv_month, wv_day);
			}
		};
		wv_year.addChangingListener(wheelListener_year);
		wv_month.addChangingListener(wheelListener_month);

		Button btn_sure = (Button) view.findViewById(R.id.btn_datetime_sure);
		Button btn_cancel = (Button) view
				.findViewById(R.id.btn_datetime_cancel);
		// 确定
		btn_sure.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				// 如果是个数,则显示为"02"的样式
				String parten = "00";
				DecimalFormat decimal = new DecimalFormat(parten);

				StringBuilder time = new StringBuilder();
				time.append(wv_year.getCurrentItem() + START_YEAR);
				time.append("-");
				time.append(decimal.format(wv_month.getCurrentItem() + 1));
				time.append("-");
				time.append(decimal.format(wv_day.getCurrentItem() + 1));
				time.append(" ");
				tv.setText(time.toString());
				showDatePicker();
			}
		});
		// 取消
		btn_cancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				showDatePicker();
			}
		});
		showDatePicker();

	}
	
	@Override
	public void setLocateInfo() {
		if(etLongitudeYF != null && etLatitudeYF != null && etelevationtYF != null) {
			etLongitudeYF.setText(GlobalVars.getInst().longitude + "");
			etLatitudeYF.setText(GlobalVars.getInst().latitude + "");
			etelevationtYF.setText(GlobalVars.getInst().altitude + "");
		}
	}

	void updateDays(int startYear, WheelView year, WheelView month,
			WheelView day) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, startYear + year.getCurrentItem());
		calendar.set(Calendar.MONTH, month.getCurrentItem());

		int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		day.setViewAdapter(new NumericWheelAdapter(this, 1, maxDays, null, "日"));
		// int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
		// day.setCurrentItem(curDay - 1, true);
	}

	private void showDatePicker() {
		if (mViewDatePicker.getVisibility() == View.GONE) {
			mViewDatePicker.setVisibility(View.VISIBLE);
			mViewDatePicker.startAnimation(mAnimationPushUpIn);
		} else {
			mViewDatePicker.setVisibility(View.GONE);
			mViewDatePicker.startAnimation(mAnimationPushUpOut);
		}
	}

	public String getCurrentTime() {
		Date dateInput = new Date(System.currentTimeMillis());
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateInput);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DATE);
		return year + "-" + month + "-" + day;
	}
	
	/**
	 * 当页面为查看样式时,更改文本框显示样式
	 */
	public void modifyEditStyle() {
		mEtXiangZhenYF.setBackgroundResource(0);
		mEtCunYF.setBackgroundResource(0);
		etGridNumberYF.setBackgroundResource(0);
		
		
		
		
		etLongitudeYF.setBackgroundResource(0);
		etLatitudeYF.setBackgroundResource(0);
		etelevationtYF.setBackgroundResource(0);
		etSlopeYF.setBackgroundResource(0);
		etenvironmentFeatureYF.setBackgroundResource(0);
		
		
		
		
		
		etquadratsNumberYF.setBackgroundResource(0);
		etquadratAreaYF.setBackgroundResource(0);
		etsmallQuadratAreaYF.setBackgroundResource(0);
		ettreeLayerCoverageYF.setBackgroundResource(0);
		etShuGanCoverageYF.setBackgroundResource(0);
		
		
		etKuZhiCoverageYF.setBackgroundResource(0);
		etGuanMuCoverageYF.setBackgroundResource(0);
		etCaoMuCoverageYF.setBackgroundResource(0);
		etcommunityYF.setBackgroundResource(0);
		etsurfaceFeaturesYF.setBackgroundResource(0);
		
		
		etInvestigatorsYF.setBackgroundResource(0);
		etinterferenceYF.setBackgroundResource(0);
		etTanXianCoverageYF.setBackgroundResource(0);
		etaspectYF.setBackgroundResource(0);
		etslopePositionYF.setBackgroundResource(0);
		
		
		this.findViewById(R.id.btnLocateYF).setVisibility(View.GONE);
		this.findViewById(R.id.btnCameraYF).setVisibility(View.GONE);
		this.findViewById(R.id.btnVedioYF).setVisibility(View.GONE);
		mSpinnerAreaYF.setBackgroundResource(0);
		metDateYF.setBackgroundResource(0);
		
		
	}

	@Override
	protected void onResume() {
		startLocation();
		super.onResume();
	}

	@Override
	protected void onPause() {
		stopLocation();
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		destroyBMapManager();
		super.onDestroy();
	}

	
	
	

}
